package es.dto;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.List;

/**
 * @author BANGO
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class BaseDto {
    /**
     * 总数
     */
    public static final String TOTAL = "total";
    /**
     * 总页数
     */
    public static final String PAGE = "pages";
    /**
     * 集合
     */
    public static final String LIST = "list";
    /**
     * 逻辑删除：0=未删除，1=删除
     */
    public static final Integer UNDELETE = 0;

    public static final Integer DELETE = 1;

    private Integer page = 1;

    private Integer size = 10;

    private Integer start;

    private String operationDevice;

    private Integer userId;

    private String key;

    private String filter;

    private String keyColor;

    private Integer order;

    private Integer orderSecond;

    private Integer sort;

    private List<Integer> idList;

    private Integer id;

    private Integer companyId;

    private List<Integer> companyIds;

    private Integer tenderId;

    private String ipAddress;

    private Integer detailType;

    private Integer searchType;

    /**
     * 收藏类型  1-公司(默认) 2-标书  3-高管
     */
    private Integer collectType = 1;
    /**
     * 邀请码
     */
    private String inviteCode;

    private String startDateTime;

    private String endDateTime;

    private Integer cityCode;

    private List<String> projectType;

    public Integer getStart() {
        if (page != null && size != null && page != 0) {
            start = (this.page - 1) * size;
        }
        return start;
    }

    public String getKey() {
        if (StringUtils.isBlank(key) && StringUtils.isNotBlank(filter)) {
            return filter;
        }
        return key;
    }

    public void setStart(Integer start) {
        this.start = start;
    }

    public static Integer calculationPages(Integer size, Integer totalCount) {
        return (totalCount + size - 1) / size;
    }
}
